package com.example.myintenttest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class FirstActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
        Button btnTiaoZhuan = findViewById(R.id.btn_tiaozhuan);
        Button btnTiaoZhuan2 = findViewById(R.id.btn_tiaozhuan2);
        btnTiaoZhuan.setOnClickListener(this);
        btnTiaoZhuan2.setOnClickListener(this);
//        btnTiaoZhuan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                    Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
//                    intent.putExtra("myname", "liujing");
//                    //startActivity(intent);
//                    startActivityForResult(intent, 1);
//
//
//            }
//        });
//        btnTiaoZhuan2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                Intent intent2 = new Intent("com.example.myintenttest.action_start");
//                intent2.addCategory("com.example.myintenttest.my_catogery");
//                startActivity(intent2);
//            }
//
//        });
//    }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_tiaozhuan:
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                intent.putExtra("myname", "liujing");
                  //startActivity(intent);
                startActivityForResult(intent, 1);

            case R.id.btn_tiaozhuan2:
                Intent intent2 = new Intent("com.example.myintenttest.action_start");
                //intent2.addCategory("com.example.myintenttest.my_catogery");
                startActivity(intent2);
                break;
            default:
                break;
        }


    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK) {
            String str = data.getStringExtra("backInfo");
            Log.i("myInfo", str);
        }
    }
}